<template>
	<view class="">
		<web-view v-if="src" :src="src" @message="getMssage" @onPostMessage="getMssage" @error="handleError"></web-view>
	</view>
</template>

<script>
	import {
		BASE_URL
	} from '@/config/request'
	export default {
		data() {
			return {
				result: {},
				src: null,
			}
		},
		onLoad({
			text,
			url,
			coverType,
			mode
		}) {
			this.src =
				`${BASE_URL}public/mini/cover-preview/#/index?userId=${this.$store.getters['userInfo'].user_id}&coverType=${coverType}&${text ? 'coverText='+text : 'url='+url}${mode ? '&mode=' + mode : ''}`
		},
		methods: {
			getMssage(e) {
				console.log('收到网页发来的消息', e.detail.data[0].result);
				uni.$emit('editCover', JSON.parse(JSON.stringify(e.detail.data[0].result)))
			},
			handleError(e) {
				console.log('网页加载失败', e);
			},
		}
	}
</script>
<style>
	page {
		background-color: #f3f3f3;
	}
</style>
<style scoped lang="scss">
	.list {
		width: 690rpx;
		height: 800rpx;
		margin: 0 auto;
		margin-bottom: 79rpx;

		image {
			width: 100%;
			height: 100%;
		}

		background-color: #fff;
	}
</style>